<?php 
require_once('../kelas/record.php');
require_once('../kelas/merk.php');
require_once('../kelas/kategori.php');
require_once('../kelas/produk.php');
require_once('../kelas/fungsi.php');
require_once('../kelas/kota.php');
require_once('../kelas/amankanParam.php');
$objKota = new Kota();
$dtGet = $objParamAman->getMethod();
$dtPost = $objParamAman->postMethod();
$on = $objFungsi->inisialisasiProses($dtGet['on']);
switch ($on) {
    case 'simpan':
        $id  = isset($dtPost['id'])?$dtPost['id']:'';
        $dtPost['aktif'] = isset($dtPost['aktif'])?1:0;
        unset($dtPost['id']);
        if($id==''){
            $dtPost['kota']= trim($dtPost['kota']);
            $objKota->get('*', array('kota'=> $dtPost['kota']),1);
            $srcKota =$objKota->execute();
            if(isset($srcKota['total']) && $srcKota['total']==0){
                $objKota->create($dtPost);
                $end = $objKota->execute();
            }
            else{
                $end = $objFungsi->arrayErrorMsg('Kota Sudah Pernah Diinput');
            }
        }
        else{
            $objKota->update($dtPost,array('id'=>$id));
            $end = $objKota->execute();
        };
        $end['data']=$dtPost;
        $end['id']=$id;
        echo json_encode($end);
        break;

    default:
        echo json_encode(array('success'=>false,'error_msg'=>'not set'));
        break;
}